package com.ncmmall.application.business.live;

import com.ncmmall.domain.business.live.LiveChannel;
import com.ncmmall.domain.business.live.LiveChannelRepository;
import com.ncmmall.domain.business.live.QLiveChannel;
import com.ncmmall.querychannel.service.QueryChannelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.sql.Timestamp;

/**
 * 直播分类管理
 *
 * @author Samuel
 * @date 2020-9-2 14:58:58
 */

@Service
@Transactional
public class LiveChannelApplication {

    @Autowired
    private LiveChannelRepository liveChannelRepository;

    @Autowired
    private QueryChannelService queryChannelService;

    /**
     * 新增
     */
    public void create(LiveChannel params) {
        params.setCreateTime(new Timestamp(System.currentTimeMillis()));
        liveChannelRepository.save(params);
    }

    /**
     * 修改
     */
    public void modify(LiveChannel params) {
        LiveChannel liveChannel = queryChannelService.findOne(QLiveChannel.liveChannel.id.eq(params.getId()), LiveChannel.class);
        liveChannel.setName(params.getName());
        liveChannelRepository.save(liveChannel);
    }

    /**
     * 删除
     */
    public void remove(LiveChannel params) {
        liveChannelRepository.delete(params);
    }
}
